package lingou.homework.postbar.controller.proto;

import com.fasterxml.jackson.databind.JsonNode;
import lingou.homework.postbar.controller.tool.JsonHelper;
import lingou.homework.postbar.domain.User;
import lingou.homework.postbar.service.enums.UserTypeEnum;
import lingou.homework.postbar.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserView {

    @Autowired
    UserService userService;

    public JsonNode attachInfo(User user){
        return JsonHelper.attach(user,
                JsonHelper.of("identity", userService.getIdentity(user.getUserId())),
                JsonHelper.of("manager", UserTypeEnum.select(user.getUserType()) == UserTypeEnum.MANAGER),
                JsonHelper.of("userTypeName", UserTypeEnum.select(user.getUserType()).getTypeName()));
    }

}
